/**
 * 
 */
package com.dsbridge.bank.business;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dsbridge.bank.dao.AccountDAO;
import com.dsbridge.bank.model.Account;

/**
 * @author Naveen
 * 
 */
@Service
public class AccountBusinessService implements AccountBusineessServiceInterface {
	@Autowired
	private AccountDAO adao;

	/* (non-Javadoc)
	 * @see com.dsbridge.bank.business.AccountBusineessServiceInter#insert(com.dsbridge.bank.model.Account)
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public Account insert(Account a) {

		int a1 = adao.insert(a);
		a.setAccountnum(a1);

		return a;

	}

	/* (non-Javadoc)
	 * @see com.dsbridge.bank.business.AccountBusineessServiceInter#update(com.dsbridge.bank.model.Account)
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public int update(Account a) {
		int a2 = 0;
		try {
			a2 = adao.update(a);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return a2;

	}

	/* (non-Javadoc)
	 * @see com.dsbridge.bank.business.AccountBusineessServiceInter#delete(com.dsbridge.bank.model.Account)
	 */
	
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public int delete(Account a) {
		int a3 = 0;
		try {
			a3 = adao.delete(a);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			// Todo
		}

		return a3;

	}

	/* (non-Javadoc)
	 * @see com.dsbridge.bank.business.AccountBusineessServiceInter#retrieveAccbyCustId(int)
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public List<Account> retrieveAccbyCustId(int customerid)
			throws SQLException {

		List<Account> ac = adao.retrieveAccbyCustId(customerid);
		return ac;

	}

}
